package automaton;

import interfaces.State;

/**
 * 
 */

/**
 * @author LE VAN LINH
 *
 */
public class StateImpl implements State, Comparable<State> {

	boolean initial;
	boolean terminal;
	String label;
	
	/**
	 * Get the initial value of State
	 */
	@Override
	public boolean initial() {		
		return this.initial;
	}

	/**
	 * Get the terminal value of State
	 */
	@Override
	public boolean terminal() {
		return this.terminal;
	}

	/**
	 * Get the label of State
	 */
	@Override
	public String label() {
		if(this.label != null)
			return this.label;
		return "";
	}

	public void setInitial(boolean initial) {
		this.initial = initial;
	}

	public void setTerminal(boolean terminal) {
		this.terminal = terminal;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public void reversed(){		
		if (initial() != terminal())
		{
			setInitial(!initial());
			setTerminal(!terminal());
		}
	}
	
	@Override
	public boolean equals(Object obj) {
		State s = (State)obj;
		return this.label().toString().compareTo(s.label().toString())==0 ? true : false;
	}
	/**
	 * Constructor of State
	 * @param initial
	 * @param terminal
	 * @param label
	 */
	public StateImpl(String label,boolean initial, boolean terminal) {		
		this.initial = initial;
		this.terminal = terminal;
		this.label = label;
	}
	
	/**
	 * Constructor
	 * @param s
	 */
	public StateImpl(State s) {		
		this.initial = s.initial();
		this.terminal = s.terminal();
		this.label = (String) s.label();
	}

	@Override
	public String toString() {
		System.out.println(this.label);
		return super.toString();
	}

	@Override
	public int compareTo(State o) {		
		return this.label.compareTo(o.label().toString());
	}
}
